﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using WisDom.SmartTMS.Entity;
using WisDom.SmartTMS.EntityFrameworkCore;
using WisDom.SmartTMS.Data;
using WisDom.SmartTMS.Enums;

namespace WisDom.SmartTMS.Repository
{
    /// <summary>
    /// 业务审批根聚合仓储实现
    /// </summary>
    public class BusinessAuditRepository :EfCoreRepository<SmartTMSDbContext, Audit, Guid>, 
                                          IBusinessAuditRepository
    {
        //构造方法
        public BusinessAuditRepository(IDbContextProvider<SmartTMSDbContext> contextProvider)
            :base(contextProvider)
        {

        }

        /// <summary>
        /// 根据Id获取审核主记录
        /// </summary>
        /// <param name="Id">主键</param>
        /// <param name="businessType">业务类型</param>
        /// <returns></returns>
        public IQueryable<Audit> GetAuditById(Guid id, BusinessType businessType)
        {
            return this.Where(a => a.Id == id && a.BusinessTypeCode == businessType)
                              .Include(a => a.AuditLogs)  //要返回审核日志明细（贪懒加载）
                              .AsQueryable();
        }

        /// <summary>
        /// 返回该业务类型所有的审核主信息
        /// </summary>
        /// <param name="businessType"></param>
        /// <returns></returns>
        public IQueryable<Audit> GetAuditList(BusinessType businessType)
        {
            return this.Where(a => a.BusinessTypeCode == businessType)
                       .AsQueryable();
        }


    }
}
